package com.aaa.day05;

import java.util.Arrays;
import java.util.List;

/**
 * @author ：Teacher陈（86521760@qq.com）
 * @date ：Created in 2024/11/15 14:34
 * @description：数组工具类
 * @modified By：
 * @version: 1.0
 */
public class MyArrays {
    public static void main(String[] args) {
        //数组的长度不足，需要扩容
       /* int [] a={1,2,3,4};
        System.out.println("老数组");
        for (int i = 0; i < a.length; i++) {
            System.out.println(a[i]);
        }*/
        //第一种扩容方案,copyOf,第一个参数是原始数组，第二个参数是新数组的长度，如果长度大于原数组长度，罗荣
        //如果长度小于原始数组的长度，缩小数组
       /* int[] newArray = Arrays.copyOf(a, 3);
        System.out.println("新数组");
        for (int i = 0; i < newArray.length; i++) {
            System.out.println(newArray[i]);
        }*/
      /*  newArray[4]=5;
        for (int i = 0; i < newArray.length; i++) {
            System.out.println(newArray[i]);
        }*/
        //copyOfRange截取数组，第一参数是原始数组，第二个参数截取的起始下标，第三个参数是结束下标（不包含本身）
        /*int[] newArray = Arrays.copyOfRange(a, 0, 2);
        System.out.println("新数组");
        for (int i = 0; i < newArray.length; i++) {
            System.out.println(newArray[i]);
        }*/
    /*    int [] b={11,12,13,14,15};*/
      /*  for (int i = 0; i < b.length; i++) {
            if(b[i]==14){
                System.out.println("下标："+i);
            }
        }*/
      /*  int i = Arrays.binarySearch(b, 14);
        System.out.println(i);*/
        int [] c={34,12,23,45,35};
        System.out.println("排序之前：");
        for (int i = 0; i < c.length; i++) {
            System.out.println(c[i]);
        }
       /* for (int i = 1; i < c.length ; i++) {
            for (int j = 0; j < c.length-i; j++) {
                //交换
                if(c[j]>c[j+1]){
                    int temp=c[j];
                    c[j]=c[j+1];
                    c[j+1]=temp;
                }
            }
        }*/
        Arrays.sort(c);
        System.out.println("排序之后：");
        for (int i = 0; i < c.length; i++) {
            System.out.println(c[i]);
        }

    }
}
